﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;

namespace WFTest
{
    public partial class MainForm : Form
    {
        public List<TreeNode> list;
        public MainForm()
        {
            InitializeComponent();
            this.IsMdiContainer = true;
            //测试用例菜单项
            list = new List<TreeNode>()
            {
                new TreeNode("Execl操作") {Tag=typeof(Form12),NodeFont=new Font("微软雅黑",9) } ,
                new TreeNode("文件操作") {Tag=typeof(FileTest),NodeFont=new Font("微软雅黑",9) } ,
            };

            //顶级菜单项
            TreeNode TopNode = new TreeNode("测试用例", list.ToArray());
            this.treeView1.Nodes.Add(TopNode);
            this.treeView1.NodeMouseDoubleClick += TreeView1_NodeMouseDoubleClick; 
        }

        private void TreeView1_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            try
            {
                if (e.Node.Tag is Type type)
                {
                    //DockContent form =(DockContent)type.GetConstructors()[0].Invoke(null);
                    DockContent form = (DockContent)Activator.CreateInstance(type);
                    form.Text = type.Name;
                    form.Show(dockPanel1);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }


        /// <summary>
        /// 点击窗口关闭将窗口隐藏至小图标窗口
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MainForm_FormClosing_1(object sender, FormClosingEventArgs e)
        {
            e.Cancel = true;
            this.Hide();
            notifyIcon1.Visible = true;
        }

        /// <summary>
        /// 双击小图标展开窗口
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            this.Show();
            this.WindowState = FormWindowState.Normal;
            notifyIcon1.Visible = false;
            this.Activate();
        }


        //private void ShowMenuStrip_Click(object sender, EventArgs e)
        //{
        //    this.Show();
        //    this.WindowState = FormWindowState.Normal;
        //    notifyIcon1.Visible = false;
        //    this.Activate();
        //}

        /// <summary>
        /// 点击小图标右键退出触发窗口关闭
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ExitMenuItem_Click(object sender, EventArgs e)
        {
            CloseForm();
        }

        private void CloseForm()
        {
            DialogResult ShowMessage = MessageBox.Show("确定要退出打印服务控制台吗？", "操作提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (ShowMessage == DialogResult.Yes)
            {
                this.Dispose();
                Application.Exit();
            }
        }
    }



}
